<?php

namespace app\common\model\Coupon;

use think\Model;

class Receive extends Model
{
    // 表名
    protected $name = 'coupon_receive';
    // 忽略数据表不存在的字段
    protected $field = true;
    // 设置返回的结果类型
    protected $resultSetType = 'collection';
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'createtime';
    //禁止写入时间字段
    protected $updateTime = false;
    // 软删除的字段
    protected $deleteTime = false;
    // 追加属性
    protected $append = [
        'createDate',
        'coupon',
        'business'
    ];
    public function getCreateDateAttr($value,$data)
    {
        if(!isset($data['createtime']))return;
        return date('Y-m-d',$data['createtime']);
    }
    public function getCouponAttr()
    {
        return $this->hasOne('coupon','id','cid')->find()->toArray();
    }
    public function getBusinessAttr()
    {
        return $this->hasOne('app\common\model\Business\Business','id','busid')->find()->toArray();
    }
    public function coupon()
    {
        return $this->belongsTo(Coupon::class,'cid','id',[],'left')->setEagerlyType(0);
    }
}
